﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebAuto
{
    public partial class IERecorderTestData : Form
    {
        private IERecorder _ieRecorderForm;
        public IERecorderTestData(IERecorder ieRecorderForm)
        {
            _ieRecorderForm = ieRecorderForm;
            
            InitializeComponent();
        }

        private void IERecorderTestData_Load(object sender, EventArgs e)
        {
            _populateFields(_ieRecorderForm.GetTestLines());
        }

        private void _populateFields(RichTextBox rtb)
        {
            rtb.SelectionStart = 0;
            if (!rtb.Text.Contains("#0"))
            {
                string[] firstLineArray = rtb.Text.Split('|')[1].Split(',');
                txtBrowser.Text = firstLineArray[0];
                txtTestName.Text = firstLineArray[1];
                txtTestPhysicalFileName.Text = firstLineArray[2];
                txtTestDescription.Text = firstLineArray[3];
                txtStartURL.Text = firstLineArray[4];
                txtTestResultsFolder.Text = firstLineArray[5];
                txtTestRepo.Text = firstLineArray[6];
                txtSQLConnectionString.Text = firstLineArray[7];
                txtTestFailURL.Text = firstLineArray[8];
                txtIterations.Text = firstLineArray[9];
                txtExcelFileData.Text = firstLineArray[10];
            }else
            {
                txtStartURL.Text = _ieRecorderForm.GetURL();
                txtTestName.Text = "EnterTestName";
                txtTestPhysicalFileName.Text = "Enter Test Physical Name.txt";
                txtTestDescription.Text = "Enter some description";
                txtTestResultsFolder.Text = "Enter Test results folder location";
                txtTestRepo.Text = "Enter Test repo folder location";
            }
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
            int iterations = 1;
            try
            {
                if (txtIterations.Text.Contains("."))
                {
                    iterations = Convert.ToInt32(txtIterations.Text.Split('.')[0]);
                }else
                {
                    iterations = Convert.ToInt32(txtIterations.Text);    
                }
                
            }catch
            {
                
            }
            _ieRecorderForm.DebugTest(txtBrowser.Text, txtTestName.Text, txtTestPhysicalFileName.Text,
                                      txtTestDescription.Text, txtStartURL.Text, txtTestResultsFolder.Text,
                                      txtTestRepo.Text, txtSQLConnectionString.Text, txtTestFailURL.Text, iterations,txtExcelFileData.Text);

            this.Close();
        }
    }
}
